<!--
- Author:  LiShibin.
- Date:    2017/8/2 0002.
- File:    wxRelation.
-->
<template>
  <div class="Web_Box">
    <div @click="back" class="Topmenu"><i class="iconfont icon-youjiantou"><a href=""></a></i>
      <h1>注册</h1>
      <span></span>
    </div>
    <div class="login_dl">
      <div class="login_ipt1">
        <i class="iconfont icon-denglu_shoujihao1"></i><input type="number" v-model="mobile" placeholder="输入手机号">
        <span style="width: 120px;">
          <message-code type="2" :tel="mobile" :callback="handleMessageCode"></message-code>
        </span>
      </div>
      <div class="login_ipt1">
        <i class="iconfont icon-wangjimima_yanzhengma"></i><input type="number" v-model="code" placeholder="输入验证码">
      </div>
      <div class="login_ipt1">
        <i class="iconfont icon-denglu_mima"></i><input type="password" v-model="pwd" placeholder="输入密码(由任意6-12位数字、字母组成)">
      </div>
      <p style="font-size:12px;">注册即代表您同意 <span style="float:none;">《TAOZI淘只用户注册协议》</span></p>
    </div>
    <div class="login_btn1" style="padding: 3rem 10px;">
      <span @click="submitRegist">提交</span>
    </div>
  </div>
</template>

<script>
  import messageCode from '../../components/message-code.vue'
  import {mapModules} from 'vuet'

  export default{
    mixins: [
      mapModules({wxInfo: 'wxInfo'})
    ],
    data() {
      return {
        from: null,
        mobile: '',
        code: '',
        pwd: ''
      }
    },
    components: {
      'message-code': messageCode
    },
    created() {
      console.log('wxInfo', this.wxInfo)
    },
    methods: {
      back() {
        console.log(123, this.from)
        this.$router.replace({name: this.from || 'login-password'})
      },
      submitRegist() {
        if (this.inRegister) return
        if (!this.$validator.phone(this.mobile)) {
          this.$toast('请输入正确的手机号！')
          return
        }
        if (!/^[\w]{6,12}$/.test(this.pwd)) {
          this.$toast('请设置6-12位数字或字母密码！')
          return
        }
        if (this.code == '') {
          this.$toast('请输入短信验证码！')
          return
        }
        this.inRegister = true
        var fkmid = window.localStorage.getItem('fkmid') || this.$route.query.fkmid || this.$utils.getQueryString('fkmid') || ''
        this.$request.register(this.mobile, this.pwd, this.code, fkmid).then(data => {
          this.$toast('注册成功！', 2000)
          setTimeout(() => {
            this.inRegister = false
            this.gotoLoginPwd()
          }, 2000)
        }).catch(e => {
          this.$toast('失败:' + e.msg)
          this.inRegister = false
        })
      },
      handleMessageCode(code) {
        this.check_mobile = code
      },
      gotoLoginPwd() {
        this.$router.replace({name: 'login-password'})
      }
    }
  }
</script>

<style>

</style>
